package work;

public class homework2 {
    public static void main(String[] args) {

        new T2().start();
        new T2().start();
    }
}


class T2 extends Thread {
    private static int Money = 10000;
    private static Object obj = new Object();

    @Override
    public synchronized void run() {
        while (true) {
            synchronized (obj) {
                if (Money <= 0) {
                    System.out.println("无存款...");
                    break;
                }
                System.out.println("用户:" + Thread.currentThread().getName() + " 取款:1000" + " 剩余:" + (Money -= 1000));
            }
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}